﻿using System;
using System.Drawing;
using SlimDX.Direct2D;
using SlimDX.Direct3D11;
using SlimDX.DXGI;
using SlimMath;
using Factory = SlimDX.Direct2D.Factory;

namespace JamesZhao.Engine.Graphics.Surfaces
{
    public enum TextureTargetMode
    {
        Managed, //resizes texture / recreate everything upon resizing 
        Raw //doesn't resize
    }

    public abstract class Surface
    {
        private Size _baseSize;
        private SampleDescription _sampleDescription = new SampleDescription(1, 0);
        private bool _cpuReadable;

        public SampleDescription SampleDescription
        {
            get { return _sampleDescription; }
            set
            {
                _sampleDescription = value;
                Initialize();
            }
        }

        public double WidthRatio { get; set; }
        public double HeightRatio { get; set; }

        public Texture2D Texture { get; set; }

        public bool CpuReadable
        {
            get { return _cpuReadable; }
            set
            {
                _cpuReadable = value;
                Initialize();
            }
        }

        public Size BaseSize
        {
            get { return _baseSize; }
            set
            {
                _baseSize = value;
                Initialize();
            }
        }

        public Size ActualSize
        {
            get
            {
                return new Size((int) Math.Ceiling(BaseSize.Width*WidthRatio),
                                (int) Math.Ceiling(BaseSize.Height*HeightRatio));
            }
        }

        public TextureTargetMode Mode { get; set; }
        public GraphicsDevice Device { get; set; }
        public string Name { get; set; }

        public abstract void Initialize();
        public abstract void DestroyTexture();
        public abstract void DestroyViews();

    }
}